package exe;

/**
 * @author oldliu
 * @since 1.0
 */
public class DelArray {
    public static void main(String[] args) {
        //从数组中删除指定的值
        String ar[]={"dog","snake","pig","cat","cow","goat"};
        String delname="pig";//要删除的值
        for (int i = 0; i < ar.length; i++) {
            if(ar[i].equals(delname)){
                //从i这个位置开始，后面的每一个往前移动一位
                for(int j=i;j<ar.length-1;j++){
                    ar[j]=ar[j+1];
                }
                ar[ar.length-1]=null;//最后一个置空
                break;
            }
        }
        for (int i = 0; i < ar.length; i++) {
            System.out.print(ar[i]+" ");
        }
    }
}
